Replace the autorelease pools used for each drawing context and in
authorRichard Hult <richard@imendio.com>
Mon, 10 Dec 2007 20:22:08 +0000 (20:22 +0000)
committerRichard Hult <rhult@src.gnome.org>
Mon, 10 Dec 2007 20:22:08 +0000 (20:22 +0000)
2007-12-10  Richard Hult  <richard@imendio.com>

* gdk/quartz/gdkdrawable-quartz.c:
(gdk_quartz_drawable_get_context),
(gdk_quartz_drawable_release_context):
* gdk/quartz/gdkeventloop-quartz.c: (gdk_event_prepare),
(gdk_event_check), (gdk_event_dispatch), (poll_func):
* gdk/quartz/gdkwindow-quartz.h: Replace the autorelease pools
used for each drawing context and in prepare, dispatch and poll
with one that exists across each main loop iteration. Fixes leaks
on leopard and protects against future leaks introduce when the
underlying system changes again (bug #492977).

svn path=/trunk/; revision=19149

ChangeLog
gdk/quartz/gdkdrawable-quartz.c
gdk/quartz/gdkeventloop-quartz.c
gdk/quartz/gdkwindow-quartz.h

index 164a55cfc3fe151b0cf7d8a9ddfa3237bfdbf73d..0e3d5afa02d79fa902285687f89c2e3dd28f07ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-12-10  Richard Hult  <richard@imendio.com>
+
+       * gdk/quartz/gdkdrawable-quartz.c:
+       (gdk_quartz_drawable_get_context),
+       (gdk_quartz_drawable_release_context):
+       * gdk/quartz/gdkeventloop-quartz.c: (gdk_event_prepare),
+       (gdk_event_check), (gdk_event_dispatch), (poll_func):
+       * gdk/quartz/gdkwindow-quartz.h: Replace the autorelease pools
+       used for each drawing context and in prepare, dispatch and poll
+       with one that exists across each main loop iteration. Fixes leaks
+       on leopard and protects against future leaks introduce when the
+       underlying system changes again (bug #492977).
+
 2007-12-10  Richard Hult  <richard@imendio.com>
 
        * gdk/quartz/gdkwindow-quartz.c: (move_resize_window_internal):
index 7e1172fc0bd3547d23ada1db6cefcb8060233690..7bcda9035ccbf99a61946c6fea5031833e6f9ac8 100644 (file)
@@ -687,14 +687,8 @@ gdk_quartz_drawable_get_context (GdkDrawable *drawable,
        */
       if (window_impl->in_paint_rect_count == 0)
        {
-         window_impl->pool = [[NSAutoreleasePool alloc] init];
          if (![window_impl->view lockFocusIfCanDraw])
-           {
-             [window_impl->pool release];
-             window_impl->pool = NULL;
-
-             return NULL;
-           }
+            return NULL;
        }
 
       cg_context = [[NSGraphicsContext currentContext] graphicsPort];
@@ -767,15 +761,7 @@ gdk_quartz_drawable_release_context (GdkDrawable  *drawable,
 
       /* See comment in gdk_quartz_drawable_get_context(). */
       if (window_impl->in_paint_rect_count == 0)
-       {
-         [window_impl->view unlockFocus];
-
-         if (window_impl->pool)
-           {
-             [window_impl->pool release];
-             window_impl->pool = NULL;
-           }
-       }
+        [window_impl->view unlockFocus];
     }
   else if (GDK_IS_PIXMAP_IMPL_QUARTZ (drawable))
     CGContextRelease (cg_context);
index a696a39e75287158d77dde2ff1721ed3b454615e..bb14a13f3256318f53bd017d168df78b84581d04 100644 (file)
@@ -23,6 +23,7 @@ static GPollFD *pipe_pollfd;
 static guint n_pollfds;
 static CFRunLoopSourceRef select_main_thread_source;
 static CFRunLoopRef main_thread_run_loop;
+static NSAutoreleasePool *autorelease_pool;
 
 gboolean
 _gdk_quartz_event_loop_check_pending (void)
@@ -56,8 +57,6 @@ gdk_event_prepare (GSource *source,
 
   GDK_THREADS_ENTER ();
   
-  GDK_QUARTZ_ALLOC_POOL;
-
   *timeout = -1;
 
   event = [NSApp nextEventMatchingMask: NSAnyEventMask
@@ -68,8 +67,6 @@ gdk_event_prepare (GSource *source,
   retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
            event != NULL);
 
-  GDK_QUARTZ_RELEASE_POOL;
-
   GDK_THREADS_LEAVE ();
 
   return retval;
@@ -82,6 +79,10 @@ gdk_event_check (GSource *source)
 
   GDK_THREADS_ENTER ();
 
+  if (autorelease_pool)
+    [autorelease_pool release];
+  autorelease_pool = [[NSAutoreleasePool alloc] init];
+
   if (_gdk_event_queue_find_first (_gdk_display) != NULL ||
       _gdk_quartz_event_loop_check_pending ())
     retval = TRUE;
@@ -102,8 +103,6 @@ gdk_event_dispatch (GSource     *source,
 
   GDK_THREADS_ENTER ();
 
-  GDK_QUARTZ_ALLOC_POOL;
-
   _gdk_events_queue (_gdk_display);
 
   event = _gdk_event_unqueue (_gdk_display);
@@ -116,8 +115,6 @@ gdk_event_dispatch (GSource     *source,
       gdk_event_free (event);
     }
 
-  GDK_QUARTZ_RELEASE_POOL;
-
   GDK_THREADS_LEAVE ();
 
   return TRUE;
@@ -201,8 +198,6 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_)
   int n_active = 0;
   int i;
 
-  GDK_QUARTZ_ALLOC_POOL;
-
   if (nfds > 1)
     {
       if (!select_thread) {
@@ -306,8 +301,6 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_)
       n_active ++;
     }
 
-  GDK_QUARTZ_RELEASE_POOL;
-
   return n_active;
 }
 
@@ -327,6 +320,7 @@ _gdk_quartz_event_loop_init (void)
 
   old_poll_func = g_main_context_get_poll_func (NULL);
   g_main_context_set_poll_func (NULL, poll_func);  
+
+  autorelease_pool = [[NSAutoreleasePool alloc] init];
 }
 
index 090c0cca0ffd5f3f626e841ca394a5a678ace653..b3e3fb9db2430020003ee31c43c4f82264d8580b 100644 (file)
@@ -54,11 +54,6 @@ struct _GdkWindowImplQuartz
 
   GdkWindowTypeHint type_hint;
 
-  /* This is the autorelease pool which is retained
-   * while the context is being held 
-   */
-  NSAutoreleasePool *pool;
-
   NSCursor *nscursor;
 
   GdkRegion *paint_clip_region;